package be.rivendale.renderer.mk2;

import be.rivendale.renderer.mk2.data.Rectangle;

import java.util.List;

public class ProducerStatistics {
    private long startTime;
    private long stopTime;
    private List<Rectangle> workInProgress;
    private int initialWorkSize;
    private double ratio;

    public ProducerStatistics(List<Rectangle> rectangles) {
        this.startTime = System.nanoTime();
        this.workInProgress = rectangles;
        this.initialWorkSize = rectangles.size();
    }

    public int getInitialWorkSize() {
        return initialWorkSize;
    }

    public boolean isComplete() {
        return workInProgress.isEmpty();
    }

    public boolean updatePendingWork(Rectangle rectangle) {
        if(workInProgress.remove(rectangle) && workInProgress.isEmpty()) {
            this.stopTime = System.nanoTime();
            return true;
        } else {
            return false;
        }
    }

    public double getTotalTime() {
        return (stopTime - startTime) / 1000000.0;
    }

    public double getTotalTimePerNode() {
        return getTotalTime() / initialWorkSize;
    }

    public double getRatio() {
        return ratio;
    }

    public void setRatio(double ratio) {
        this.ratio = ratio;
    }
}
